﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using System.Xml;

namespace TemplateH4.admin
{
    public partial class QLGiaoDien_Logo: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));

            XmlNode root = doc.DocumentElement;
            imglogo.ImageUrl = "~/admin/images/upload/" + root.SelectSingleNode("logo").ChildNodes[0].Value;

            //Response.Write(imglogo.ImageUrl);

        }

        protected void btnuploadlogo_Click(object sender, EventArgs e)
        {

            String filepath = logoupload.PostedFile.FileName;
            String filename = Path.GetFileName(filepath);
            logoupload.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);


            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            //XmlNode node = root.SelectSingleNode("logo").ChildNodes[0];
            XmlNode old = root.SelectSingleNode("logo");
            XmlElement logo = doc.CreateElement("logo");
            logo.InnerText = filename;
            root.ReplaceChild(logo, old);
            
            
            imglogo.ImageUrl = "~/admin/images/upload/" + filename;

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);
            
            
        }
    }
}
